from flask import Flask,render_template
from dto.user import User
import datetime

app = Flask(__name__)


@app.get("/for")
def for_statements():
    books=[
        {'name':'三国演义','author':'罗贯中','price':100},
        {'name':'水浒传','author':'施耐庵','price':99},
        {'name':'红楼梦','author':'曹雪芹','price':101},
        {'name':'西游记','author':'吴承恩','price':102}
    ]
    return render_template("for.html",books=books)


@app.get('/if')
def if_statement():
    age = 18
    return render_template("if.html",age=age)


@app.get('/')
def hello():
    return 'hello world'


@app.get('/child1')
def child1():
    return render_template('child1.html')


@app.get('/child2')
def child2():
    return render_template('child2.html')


@app.get("/boot")
def boot_static():
    return render_template('teststatic.html')


@app.get('/index')
def index():
    return render_template("index.html")


@app.get('/variable')
def variable():
    hobby = '游戏'
    user = User("张三","2586440599@qq.com")
    person = {'username':'李四','age':18}
    context = {
        'user':user,
        'person':person,
        'hobby':hobby,
        'city':'贵阳'
    }
    return render_template("variable.html",**context)


@app.get("/filter")
def length():
    name = '李铭晗一世'
    time = datetime.datetime.now()
    list = ["curry","kobe",'james']
    return render_template("filter.html",name=name,time=time,var='user',list=list)


@app.get("/testdev")
def test():
    user = User("王五",'18935268954@126.com')
    return render_template('testDev.html',user=user)


def datetime_format(value,format='%Y-%m-%d %H:%M'):
    return value.strftime(format)


app.add_template_filter(datetime_format,'dformat')

if __name__ == '__main__':
    app.run(debug=True)